// pages/geo/geo.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    address:'广州南方学院',
    iconList: [{
      icon: 'shopfill',
      color: 'red',
      badge: 120,
      name: '美食',
      poicode:'050000'
    }, {
      icon: 'recordfill',
      color: 'orange',
      badge: 1,
      name: '风景',
      poicode:'110000'
    }, {
      icon: 'cartfill',
      color: 'yellow',
      badge: 0,
      name: '购物',
      poicode:'060000'
    }, {
      icon: 'read',
      color: 'olive',
      badge: 22,
      name: '科教',
      poicode:'140000'
    }, {
      icon: 'safe',
      color: 'cyan',
      badge: 0,
      name: '医疗',
      poicode:'090000'
    }, {
      icon: 'homefill',
      color: 'blue',
      badge: 0,
      name: '住宿',
      poicode:'100000'
    }, {
      icon: 'discoverfill',
      color: 'purple',
      badge: 0,
      name: '发现',
      poicode:'070000'
    }, {
      icon: 'questionfill',
      color: 'mauve',
      badge: 0,
      name: '帮助',
      poicode:'130000'
    }, {
      icon: 'commandfill',
      color: 'purple',
      badge: 0,
      name: '问答'
    }, {
      icon: 'brandfill',
      color: 'mauve',
      badge: 0,
      name: '版权'
    }],
    gridCol:4,
    pois:[]

  },

  formSubmit(e) {
    console.log('form发生了submit事件，携带数据为：', e.detail.value.user_data)
    var that = this
    wx.request({
      url: 'https://restapi.amap.com/v3/place/text?parameters', //仅为示例，并非真实的接口地址
      data: {
        key: 'ebc95001843573926542a84152ed3a49',
        keywords: e.detail.value.user_data
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        that.setData({
          address:e.detail.value.user_data
        })
        console.log(res.data.pois[0].location) //获取搜索信息的最相关性的地址坐标
        wx.request({
          url: 'https://restapi.amap.com/v3/place/around?parameters ', //仅为示例，并非真实的接口地址
          data: {
            key: 'ebc95001843573926542a84152ed3a49',
            location: res.data.pois[0].location
          },
          header: {
            'content-type': 'application/json' // 默认值
          },
          success (res) {
            console.log(res.data.pois)
            that.setData({
              pois:res.data.pois
            })
          }
        })

      }
    })
  },

  categroy: function(event) {
    console.log(event.currentTarget.dataset.cate)
    var that = this
    wx.request({
      url: 'https://restapi.amap.com/v3/place/text?parameters', //仅为示例，并非真实的接口地址
      data: {
        key: 'edbc4cbecb3a8e708b8e67ea23b57e3c',
        keywords: this.data.address
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        console.log(res.data.pois[0].location) //获取搜索信息的最相关性的地址坐标
        wx.request({
          url: 'https://restapi.amap.com/v3/place/around?parameters ', //仅为示例，并非真实的接口地址
          data: {
            key: 'edbc4cbecb3a8e708b8e67ea23b57e3c',
            location: res.data.pois[0].location,
            types:event.currentTarget.dataset.cate
          },
          header: {
            'content-type': 'application/json' // 默认值
          },
          success (res) {
            console.log(res.data.pois)
            that.setData({
              pois:res.data.pois
            })
          }
        })

      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this
    wx.request({
      url: 'https://restapi.amap.com/v3/place/text?parameters', //仅为示例，并非真实的接口地址
      data: {
        key: 'ebc95001843573926542a84152ed3a49',
        keywords: '广州南方学院'
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        console.log(res.data.pois[0].location)  //获取搜索信息的最相关的地址坐标

        wx.request({
          url: 'https://restapi.amap.com/v3/place/around?parameters ', //仅为示例，并非真实的接口地址
          data: {
            key: 'ebc95001843573926542a84152ed3a49',
            location: res.data.pois[0].location
          },
          header: {
            'content-type': 'application/json' // 默认值
          },
          success (res) {
            console.log(res.data.pois)
            that.setData({
              pois:res.data.pois
            })
          }
        })

      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})